package game.views;

import game.shader.LoadRoleHeadShader;
import hx.display.BitmapData;
import game.data.XlsData;
import hx.ui.UIManager;
import game.views.LoadRoleView.LoadRoleViewPlayer;
import hx.display.Box;

/**
 * 单个角色挑战VS组件
 */
@:build(hx.macro.UIBuilder.build("assets/views/LoadRoleItem.xml"))
class LoadRoleItem extends Box {
	/**
	 * 设置显示数据
	 * @param data 
	 * @param isFilp 
	 */
	public function setData(data:LoadRoleViewPlayer, isFilp:Bool = false) {
		displayBox.scaleX = 1;
		if (isFilp) {
			var w = this.width;
			displayBox.scaleX = -1;
			displayBox.x = w;
		}
		var id = this.name.charAt(1);
		this.bg.data = UIManager.getBitmapData("LoadRoleViewAtlas:" + (isFilp ? "blue" : "red") + "_frame");
		this.playerId.data = UIManager.getBitmapData("LoadRoleViewAtlas:" + (isFilp ? "blue" : "red") + id);
		this.head.data = UIManager.getBitmapData(isFilp ? "blue_mask" : "red_mask");
		var roleData = XlsData.roles.getDataByRoleid(data.id);
		if (roleData != null) {
			this.nameLabel.data = roleData.name;
		} else {
			this.nameLabel.data = "无";
		}
		this.head.visible = false;
	}

	/**
	 * 更新头像
	 * @param bitmapData 
	 */
	public function updateHead(bitmapData:BitmapData):Void {
		this.head.visible = true;
		this.head.shader = new LoadRoleHeadShader(bitmapData);
	}
}
